/**
 * Created by sean on 15/10/24.
 */
(function ($) {
    'use strict';
    var Dialog = function ($el, options) {
        this.$el = $el;
        this.options = options;
    };
    Dialog.DEFAULTS = {
        title: '提示',
        content: '',
        buttonText: '确定'
    };
    // init html
    Dialog.prototype.initHtml = function () {
        var $div = this.$el;
        var _this = this;
        var html = '<div class="dialog-container">'
            + '<div class="dialog-content">'
            + '<section>'
            + '<header>' + _this.options.title + '</header>'
            + '<section>' + _this.options.content + '</section>'
            + '</section>'
            + '<footer>'
            + '<a href="javascript:void(0);"><div>' + _this.options.buttonText + '</div></a>'
            + '</footer>'
            + '</div>'
            + '</div>';
        $div.append(html);
        _this.bindEvent($div);
    };

    // bind event
    Dialog.prototype.bindEvent = function ($div) {
        var _this = this;
        $div.find('a').on('click', function () {
            $(this).parent().css({"background-color": "#E2E2E2",
                "border-bottom-left-radius": "20px",
                "border-bottom-right-radius": "20px"});
            setTimeout(function () {
                $div.find('.dialog-container').remove();
            }, 200);
        });
    };

    // init function
    Dialog.prototype.show = function () {
        this.initHtml();
    };

    // init function
    Dialog.prototype.hide = function () {
        this.$el.find('.dialog-container').remove();
    };

    $.fn.Dialog = function (options) {
        options = $.extend(Dialog.DEFAULTS, options);
        return new Dialog(this, options);
    };
})(jQuery);
